package com.animal.controller;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.animal.dao.ExpManage;

public class ExpServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public ExpServlet() {
		super();
	}
	
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=utf-8");
		request.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		
		String dos = request.getParameter("do");

		if (dos == null || dos.equals("")) {
			
			//out.print("<script>window.location='ExperimentalFileManagement.jsp';</script>");
			
			response.sendRedirect("ExperimentalFileManagement.jsp");
			
		}
		if (dos.equals("archive")) {
			
			String id = request.getParameter("id");
			
			boolean b = ExpManage.updateState(id, "已审核");
			
			if(b){
				out.print("<script>alert('审核成功!');window.location='ExperimentalFileManagement.jsp';</script>");
			}
			else{
				out.print("<script>alert('审核失败!');</script>");
			}
			return;
		}
		
		if(dos.equals("del")){
			String id = request.getParameter("id");
			
			boolean b = ExpManage.delete(id);
			
			if(b){
				out.print("<script>alert('删除成功!');window.location='ExperimentalFileManagement.jsp';</script>");
				
			}else{
				out.print("<script>alert('删除失败!');</script>");
			}
			return;
		}

	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		PrintWriter out = response.getWriter();

		doGet(request,response);
	}

	public void init() throws ServletException {
		// Put your code here
	}
}
